package com.kkd.kkdapp.adapter;

import java.util.List;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.activity.PaymentActivity;
import com.kkd.kkdapp.adapter.PaingCreditDetailAdapter.ViewHolder;
import com.kkd.kkdapp.http.entity.PaingCreditDetailList;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PaidCreditDetailAdapter extends BaseAdapter {

	private Context context;
	private List<PaingCreditDetailList> mList;

	public PaidCreditDetailAdapter(Context context,
			List<PaingCreditDetailList> mList) {
		this.context = context;
		this.mList = mList;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder mViewHolder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.paidcreditcetail_item,
					null);
			mViewHolder = new ViewHolder();
			convertView.setTag(mViewHolder);
			mViewHolder.repayment = (TextView) convertView
					.findViewById(R.id.repayment);
			mViewHolder.expect = (TextView) convertView
					.findViewById(R.id.expect_tv);
			mViewHolder.shouldpaymoney = (TextView) convertView
					.findViewById(R.id.shouldpaymoney);
			mViewHolder.bill_tv = (TextView) convertView
					.findViewById(R.id.bill);
			mViewHolder.date_tv = (TextView) convertView
					.findViewById(R.id.date_tv);
			mViewHolder.desc_tv = (TextView) convertView
					.findViewById(R.id.desc_tv);
			mViewHolder.amortizedloans = (TextView) convertView
					.findViewById(R.id.amortizedloans);
		} else {
			mViewHolder = (ViewHolder) convertView.getTag();
		}

		// 期数
		mViewHolder.expect.setTag(position);
		mViewHolder.expect.setText("第" + mList.get(position).getBill_num()
				+ "期");
		// 还款状态：还款，逾期还款，未到期
		mViewHolder.repayment.setTag(position);
		mViewHolder.repayment.setText(mList.get(position).getButton_text());
		// 应还金额
		mViewHolder.shouldpaymoney.setTag(position);
		mViewHolder.shouldpaymoney.setText("应还金额："
				+ mList.get(position).getShouldPayMoney() + "元");
		// 应还金额描述
		mViewHolder.bill_tv.setTag(position);
		mViewHolder.bill_tv.setText(mList.get(position).getBill_text());
		// 还款日期
		mViewHolder.date_tv.setTag(position);
		mViewHolder.date_tv.setText("还款日期："
				+ mList.get(position).getShouldPayDate());
		// 到期天数
		mViewHolder.desc_tv.setTag(position);
		mViewHolder.desc_tv.setText(mList.get(position).getDesc());
		mViewHolder.amortizedloans.setText("已还："
				+ mList.get(position).getHavePayMoney() + "元");
		return convertView;
	}

	class ViewHolder {
		TextView repayment;
		TextView expect;
		TextView shouldpaymoney;
		TextView bill_tv;
		TextView date_tv;
		TextView desc_tv;
		TextView amortizedloans;
	}
}
